//
//  DaLeTouVC.m
//  K8彩票
//
//  Created by zyn on 2017/6/8.
//  Copyright © 2017年 zhoubo. All rights reserved.
//

#import "DaLeTouVC.h"
#import "BallButton.h"

@interface DaLeTouVC ()<OnClickBallCallback>{
    NSMutableArray *arrayRedDatas, *arrayBlueDatas;
    NSMutableArray *arrayRed21Datas ,*arrayRed22Datas, *arrayBlue21Datas, *arrayBlue22Datas;
}
@property (weak, nonatomic) IBOutlet UIButton *btnSelectTop;
@property (weak, nonatomic) IBOutlet UIButton *btnApply;

@property (weak, nonatomic) IBOutlet UIView *viewType1;
@property (weak, nonatomic) IBOutlet UIView *viewType1Red;
@property (weak, nonatomic) IBOutlet UIView *viewType1Blue;
@property (weak, nonatomic) IBOutlet NSLayoutConstraint *layoutViewType1Height;
@property (weak, nonatomic) IBOutlet NSLayoutConstraint *layoutViewType1RedHeight;
@property (weak, nonatomic) IBOutlet NSLayoutConstraint *layoutViewType1BlueHeight;

// 胆拖
@property (weak, nonatomic) IBOutlet UIView *viewType2;
@property (weak, nonatomic) IBOutlet UIView *viewType21Red;
@property (weak, nonatomic) IBOutlet UIView *viewType22Red;
@property (weak, nonatomic) IBOutlet UIView *viewType21Blue;
@property (weak, nonatomic) IBOutlet UIView *viewType22Blue;
@property (weak, nonatomic) IBOutlet NSLayoutConstraint *layoutViewType2Height;
@property (weak, nonatomic) IBOutlet NSLayoutConstraint *layoutViewType21RedHeight;
@property (weak, nonatomic) IBOutlet NSLayoutConstraint *layoutViewType22RedHeight;
@property (weak, nonatomic) IBOutlet NSLayoutConstraint *layoutViewType21BlueHeight;
@property (weak, nonatomic) IBOutlet NSLayoutConstraint *layoutViewType22BlueHeight;

@end

@implementation DaLeTouVC

- (void)viewDidLoad {
    [super viewDidLoad];
    [self initializeView];
    [self initializeData];
}

-(void)initializeView{
    _viewType1.hidden = NO;
    _viewType2.hidden = YES;
    ((ViewController *)[UIApplication sharedApplication].keyWindow.rootViewController).mainTabbar.frame = CGRectMake(0, -49, 0, 0);
//    ((ViewController *)[UIApplication sharedApplication].keyWindow.rootViewController).mainTabbar.hidden = YES;
    
    _btnSelectTop.tag = 0;
    _btnSelectTop.layer.borderColor = [[UIColor whiteColor]CGColor];
    _btnSelectTop.layer.borderWidth = 1;
    _btnSelectTop.layer.cornerRadius = 4;
    _btnSelectTop.layer.masksToBounds = YES;
    [_btnSelectTop addTarget:self action:@selector(onClick:) forControlEvents:UIControlEventTouchUpInside];

    _layoutViewType1RedHeight.constant = (ScreenWidth()  - 8 * 12) / 7 * 5 + 12 * 6;
    _layoutViewType1BlueHeight.constant = (ScreenWidth()  - 8 * 12) / 7 * 2 + 12 * 3;
    _layoutViewType1Height.constant = (ScreenWidth()  - 8 * 12) / 7 * 5 + 12 * 6 + (ScreenWidth()  - 8 * 12) / 7 * 2 + 12 * 3 + 50;

    
    _layoutViewType21RedHeight.constant = (ScreenWidth()  - 8 * 12) / 7 * 5 + 12 * 6;
    _layoutViewType22RedHeight.constant = (ScreenWidth()  - 8 * 12) / 7 * 5 + 12 * 6;
    _layoutViewType21BlueHeight.constant = (ScreenWidth()  - 8 * 12) / 7 * 2 + 12 * 3;
    _layoutViewType22BlueHeight.constant = (ScreenWidth()  - 8 * 12) / 7 * 2 + 12 * 3;
    
//    _layoutViewType2Height.constant = ((ScreenWidth()  - 8 * 12) / 7 * 5 + 12 * 6) * 2 + ((ScreenWidth()  - 8 * 12) / 7 * 2 + 12 * 3) * 2 + 130;


}

-(void)initializeData{
    arrayRedDatas = [NSMutableArray arrayWithCapacity:0];
    arrayBlueDatas = [NSMutableArray arrayWithCapacity:0];
    arrayRed21Datas = [NSMutableArray arrayWithCapacity:0];
    arrayRed22Datas = [NSMutableArray arrayWithCapacity:0];
    arrayBlue21Datas = [NSMutableArray arrayWithCapacity:0];
    arrayBlue22Datas = [NSMutableArray arrayWithCapacity:0];
    
    // 普通
    for (int i = 1; i < 36; i ++) {
        BallButton *btn = [[BallButton alloc]initWithNumber:i type:RED_BALL];
        btn.callback = self;
        [_viewType1Red addSubview:btn];
        [arrayRedDatas addObject:btn];
    }
    
    for (int i = 1; i < 13; i++) {
        BallButton *btn = [[BallButton alloc]initWithNumber:i type:BLUE_BALL];
        btn.callback = self;
        [_viewType1Blue addSubview:btn];
        [arrayBlueDatas addObject:btn];
    }
    
    // 胆拖
    for (int i = 1; i < 36; i ++) {
        BallButton *btn = [[BallButton alloc]initWithNumber:i type:RED_BALL];
        btn.callback = self;
        [_viewType21Red addSubview:btn];
        [arrayRed21Datas addObject:btn];
    }
    for (int i = 1; i < 36; i ++) {
        BallButton *btn = [[BallButton alloc]initWithNumber:i type:RED_BALL];
        btn.callback = self;
        [_viewType22Red addSubview:btn];
        [arrayRed22Datas addObject:btn];
    }
    for (int i = 1; i < 13; i++) {
        BallButton *btn = [[BallButton alloc]initWithNumber:i type:BLUE_BALL];
        btn.callback = self;
        [_viewType21Blue addSubview:btn];
        [arrayBlue21Datas addObject:btn];
    }
    for (int i = 1; i < 13; i++) {
        BallButton *btn = [[BallButton alloc]initWithNumber:i type:BLUE_BALL];
        btn.callback = self;
        [_viewType22Blue addSubview:btn];
        [arrayBlue22Datas addObject:btn];
    }


}

- (IBAction)onClickBack:(id)sender {
    [self back];
}

-(void)onClick:(UIButton *)btn{
    switch (btn.tag) {
        case 0:
            // 选择玩法
            [self selectPlayType];
            break;
            
        default:
            break;
    }
}
- (IBAction)onClickApply:(id)sender {
    if (IS_OPEN_SWITCH) {
        [self showHint:NSLocalizedString(@"投注成功", @"投注成功")];
        
    }
    else
    {
        [self showHint:NSLocalizedString(@"请开启虚拟投注功能", @"请开启虚拟投注功能")];
    }
}

/// 弹出选择玩法选择框
-(void)selectPlayType{
    UIAlertController*alertController = [[UIAlertController alloc] init];
    UIAlertAction*alertAction = [UIAlertAction actionWithTitle:NSLocalizedString(@"取消", @"取消") style:UIAlertActionStyleCancel handler:^(UIAlertAction *action) {
    }];
    [alertController addAction:alertAction];
    
    [alertController addAction:[UIAlertAction actionWithTitle:NSLocalizedString(@"普通投注", @"普通投注") style:(UIAlertActionStyleDefault) handler:^(UIAlertAction *  action) {
        [_btnSelectTop setTitle:NSLocalizedString(@"大乐透", @"大乐透") forState:UIControlStateNormal];
        _viewType1.hidden = NO;
        _viewType2.hidden = YES;
        _layoutViewType1Height.constant = (ScreenWidth()  - 8 * 12) / 7 * 5 + 12 * 6 + (ScreenWidth()  - 8 * 12) / 7 * 2 + 12 * 3 + 50;
    }]];
    
    [alertController addAction:[UIAlertAction actionWithTitle:NSLocalizedString(@"胆拖投注", @"胆拖投注") style:UIAlertActionStyleDefault handler:^(UIAlertAction *  action) {
        [_btnSelectTop setTitle:NSLocalizedString(@"大乐透胆拖", @"大乐透胆拖") forState:UIControlStateNormal];
        _viewType1.hidden = YES;
        _viewType2.hidden = NO;
        _layoutViewType1Height.constant = ((ScreenWidth()  - 8 * 12) / 7 * 5 + 12 * 6) * 2 + ((ScreenWidth()  - 8 * 12) / 7 * 2 + 12 * 3) * 2 + 100;
    }]];
    [self presentViewController:alertController animated:YES completion:nil];
    
}


-(void)onClickBall{
    
}

@end
